# !/Scripts/python
# coding=utf-8
# @Author       : Inky
# @Date         : 2020-06-10 23:22:11
# @LastEditTime : 2020-06-10 23:22:14
# @FilePath     : /inky-ws/decision_algorithm/msf/fsmTest.py
# @Description  : FSM-Learning, testing fsm

from StateMachine import StateMachine

def start_transition(txt):
    split_txt = txt.split(' ', 1)
    word, txt = split_txt if len(split_txt) > 1 else (txt, '')

    if "Python" == word:
        newState = "Python_state"
    else:
        newState = "error_state"
    return (newState, txt)

def python_state_transition(txt):
    split_txt = txt.split(' ', 1)
    word, txt = split_txt if len(split_txt) > 1 else (txt, '')
    if "is" == word:
        newState = "is_state"
    else:
        newState = "error_state"
    return (newState, txt)

def is_state_transition(txt):
    split_txt = txt.split(' ', 1)
    word , txt = split_txt if len(split_txt) > 1 else (txt, '')
    if word == 'not':
        newState = "not_state"
    elif word in StateMachine.positive_adj:
        newState = "positive_state"
    elif word in StateMachine.negative_adj:
        newState = "negative_state"
    else:
        newState = "error_state"
    return (newState, txt)

def not_state_transition(txt):
    split_txt = txt.split(" ", 1)
    word, txt = split_txt if len(split_txt) > 1 else (txt, '')
    if word in StateMachine.negative_adj:
        newState = "positive_state"
    elif word in StateMachine.positive_adj:
        newState = "negative_state"
    else:
        newState = "error_state"
    return (newState, txt)


if __name__ == "__main__":
    fsm = StateMachine()
    fsm.add_state("Start", start_transition)
    fsm.add_state("Python_state", python_state_transition)
    fsm.add_state("is_state", is_state_transition)
    fsm.add_state("not_state", not_state_transition)
    fsm.add_state("negative_state", None, end_state = 1)
    fsm.add_state("positive_state", None, end_state = 1)
    fsm.add_state("error_state", None, end_state = 1)
    fsm.set_start("Start")

    fsm.run("Python is not fun")
    fsm.run("Python is not bad")
    fsm.run("Python is great")